package com.wondersgroup.fjzlpt.tbxt.controller.rest.jc;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.quick.framework.boot.web.wapper.QuickPrincipal;
import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.tbxt.beans.req.jcNb.QueryNbInfoReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.req.jcNb.SaveReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.resp.BaseRespBean;
import com.wondersgroup.fjzlpt.tbxt.beans.resp.jcNb.QueryNbInfoRespBean;
import com.wondersgroup.fjzlpt.tbxt.service.inter.jc.JcJbService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/jcjb")
@Api(value = "基层年报标准接口",tags = "JcNbRestController", description = "基层季报API")
public class JcJbRestController {

	@Autowired
	private JcJbService jcJbService;

	/**
	 * 保存或更新
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "保存或更新", notes = "保存或更新基层年报信息", response = BaseRespBean.class)
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public JSONObject save(HttpServletRequest request, SaveReqBean saveBean)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		return jcJbService.save(map);
	}
	/**
	 * 查询
	 * @param request
	 * @return
	 */
	@ApiOperation(value = "查询季报信息", notes = "查询基层季报填报信息", response = QueryNbInfoRespBean.class)
	@RequestMapping(value = "/queryOne",method = RequestMethod.POST)
	public JSONObject queryOne(HttpServletRequest request, QueryNbInfoReqBean queryNbInfoReqBean)
	{
		Map<String, String> map = RequestUtils.GetParameterMap(request);
		if(StringUtils.isEmpty(map.get("YLJGID"))){
			map.put("YLJGID", QuickPrincipalUtils.getPtjgID(request));
			QuickPrincipal principal = (QuickPrincipal)request.getUserPrincipal();
			JSONObject userInfo = principal.getUserInfo();
			map.putAll(JSONObject.toJavaObject(userInfo, Map.class));
		}
		return jcJbService.queryOne(map);
	}

}
